package com.simple.datax.transform.tcs;

import org.apache.xmlbeans.XmlObject;

import com.simple.datax.SimpleMessage;
import com.simple.datax.SimpleObject;
import com.simple.datax.api.TransformerException;
import com.simple.datax.transform.SimpleTransformer;
import com.simple.datax.xml.ec.EC101MessageDocument;
import com.simple.datax.xml.tcs.TCS101MessageDocument;

/**
 * @Title: Ec2TcsTransformerImpl.java
 * @Package com.simple.datax.transform.tcs
 * @Description: TODO(添加描述)
 * @author Paladin Chen
 * @date 2013-1-9 下午2:19:29
 * @version V1.0
 */
public class Ec2TcsTransformerImpl implements SimpleTransformer {
	private boolean isAcceptNull = false;

	private boolean isIgnoreBadInput = false;

	private String encoding = "UTF-8";

	@Override
	public boolean isAcceptNull() {
		return isAcceptNull;
	}

	public void setAcceptNull(boolean isAcceptNull) {
		this.isAcceptNull = isAcceptNull;
	}

	public void setIgnoreBadInput(boolean isIgnoreBadInput) {
		this.isIgnoreBadInput = isIgnoreBadInput;
	}

	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	@Override
	public String getEncoding() {
		return encoding;
	}

	@Override
	public boolean isIgnoreBadInput() {
		return isIgnoreBadInput;
	}

	@Override
	public void transform(SimpleObject src) throws TransformerException {
		transform(src, encoding);
	}

	@Override
	public void transform(SimpleObject src, String encoding) throws TransformerException {
		if (src instanceof SimpleMessage) {
			XmlObject intraDoc = ((SimpleMessage) src).getIntraDoc();

			if (intraDoc instanceof EC101MessageDocument) {
				Ec2TcsMessageTransformer e2tmsgtrans = new Ec2TcsMessageTransformer();
				TCS101MessageDocument tcsMsgDoc = e2tmsgtrans.transform((EC101MessageDocument) intraDoc);
				((SimpleMessage) src).setIntraDoc(tcsMsgDoc);

			} else {
				throw new TransformerException("The MsgType is not supported now!");
			}

		} else {
			throw new TransformerException("The Paramter MUST be SimpleMessage!");
		}

	}

}
